package com.example.service.webhook.business.qq.repository;

import com.example.service.webhook.business.qq.entity.QQRecentContactEntity;
import com.example.service.webhook.repository.base.BaseDAO;
import com.example.service.webhook.util.DateUtil;
import com.example.service.webhook.util.SequenceUtil;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;

/**
 * qq最近联系人
 * ClassName: QqRecentContactRepository    
 * date: 2016年9月9日 下午2:14:47   
 * @author yuandong  
 * @version   
 * @since JDK 1.6
 */
@Repository
public class QqRecentContactRepository extends BaseDAO<QQRecentContactEntity> {
	
	@Resource(name="templateQq")
    private JdbcTemplate jdbcTemplate;

    public JdbcTemplate getJdbcTemplate() {
		return jdbcTemplate;
	}
    
    public void saveQQRecentContact(QQRecentContactEntity entity) throws Exception  {
    	entity.setCreateTime(DateUtil.getCurrentDate());
    	entity.setLastModifyTime(DateUtil.getCurrentDate());
		this.save(entity,getTableName(entity.getUserId()));
    }
    
    
    public void deleteQQRecentContact(String userId,String qqNum){
    	String sql = "delete from "+getTableName(userId)+" where userId=? and qqNum=?";
    	this.delete(sql, new Object[]{userId,qqNum});
    }
    
    private String getTableName(String userId){
    	return "t_qq_recentcontact_"+ SequenceUtil.getTableSuffix(userId);
    }
    
    
}
